package cn.wolfcode.wolf2w.query;

import lombok.Getter;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;

import java.util.HashMap;
import java.util.Map;

@Getter
public class TravelCondition {
    private int min;    // 最小天数
    private int max;    // 最大天数
    private Direction sortType;    // 最小天数
    private String orderField;    // 最大天数

    // 游玩天数 ---对应--- 范围
    public static final Map<Integer, TravelCondition> DAY_MAP = new HashMap<>();
    // 人均消费 ---对应--- 范围
    public static final Map<Integer, TravelCondition> PER_MAP = new HashMap<>();
    // 排序类型编号 ---对应--- 数据库字段
    public static final Map<Integer, TravelCondition> ORDER_TYPE_MAP = new HashMap<>();
    // 初始化数据
    static {
        DAY_MAP.put(1, new TravelCondition(0, 3));
        DAY_MAP.put(2, new TravelCondition(4, 7));
        DAY_MAP.put(3, new TravelCondition(8, 14));
        DAY_MAP.put(4, new TravelCondition(15, Integer.MAX_VALUE));

        PER_MAP.put(1, new TravelCondition(1, 999));
        PER_MAP.put(2, new TravelCondition(1000, 6000));
        PER_MAP.put(3, new TravelCondition(6001, 20000));
        PER_MAP.put(4, new TravelCondition(20001, Integer.MAX_VALUE));

        ORDER_TYPE_MAP.put(-1, new TravelCondition(Sort.Direction.ASC, "_id"));
        ORDER_TYPE_MAP.put(1, new TravelCondition(Sort.Direction.ASC, "createTime"));
        ORDER_TYPE_MAP.put(2, new TravelCondition(Direction.DESC, "viewnum"));
    }
    // 有参构造器  范围
    public TravelCondition(int min, int max) {
        this.min = min;
        this.max = max;
    }
    // 有参构造器  取出排序的类型和需要排序的列值
    public TravelCondition(Direction sortType, String orderField) {
        this.sortType = sortType;
        this.orderField = orderField;
    }
}
